from creation_menu import creation_menu

class mediator_fake :
    def __init__ ( self ) :
        self . _creation_menu = None
        self . _hide_browser = False
        self . _creation_menu_title = None
        self . _creation_menu_create = None
        self . _creation_menu_new_name = None
        self . _creation_menu_already_exists = None
        self . _on_creation_menu_return = False
        self . _on_creation_menu_base_created = False
        self . _entry_text = None
        self . _call_history = [ ]
        self . _configured_title_text = None
        self . _configured_title_text_before_show_browser = None
        self . _configured_action_text = None
        self . _configured_action_text_before_show_browser = None
        self . _configured_action_title_name_text = None
        self . _configured_action_title_name_text_before_show_browser = None
        self . _configured_only_unique_names_mode = None
        self . _configured_only_unique_names_mode_before_show_browser = None
        self . _configured_title_text_when_no_entries = None
        self . _configured_title_text_when_no_entries_before_show_browser = None
        self . _configured_keep_action_part_when_no_entries = None
        self . _configured_keep_action_part_when_no_entries_before_show_browser = None
    def show_browser ( self ) :
        self . _configured_title_text_before_show_browser = self . _configured_title_text
        self . _configured_action_text_before_show_browser = self . _configured_action_text
        self . _configured_action_title_name_text_before_show_browser = self . _configured_action_title_name_text
        self . _configured_only_unique_names_mode_before_show_browser = self . _configured_only_unique_names_mode
        self . _configured_title_text_when_no_entries_before_show_browser = self . _configured_title_text_when_no_entries
        self . _configured_keep_action_part_when_no_entries_before_show_browser = self . _configured_keep_action_part_when_no_entries
    def hide_browser ( self ) :
        self . _hide_browser = True
    def configure_title_text_for_browser ( self , title_text ) :
        self . _configured_title_text = title_text
    def configure_action_text_for_browser ( self , action_text ) :
        self . _configured_action_text = action_text
    def configure_action_title_name_text_for_browser ( self , action_title_name_text ) :
        self . _configured_action_title_name_text = action_title_name_text
    def configure_only_unique_names_mode_for_browser ( self , already_exists_text ) :
        self . _configured_only_unique_names_mode = already_exists_text
    def configure_title_text_when_no_entries_for_browser ( self , title_text ) :
        self . _configured_title_text_when_no_entries = title_text
    def configure_keep_action_part_when_no_entries_for_browser ( self ) :
        self . _configured_keep_action_part_when_no_entries = True
    def localization_creation_menu_title ( self ) :
        return self . _creation_menu_title
    def localization_creation_menu_create ( self ) :
        return self . _creation_menu_create
    def localization_creation_menu_new_name ( self ) :
        return self . _creation_menu_new_name
    def localization_creation_menu_already_exists ( self ) :
        return self . _creation_menu_already_exists
    def on_creation_menu_return ( self ) :
        self . _on_creation_menu_return = True
    def on_creation_menu_base_created ( self ) :
        self . _call_history += [ mediator_fake . on_creation_menu_base_created ]
        self . _on_creation_menu_base_created = True
    def create_knowledge_base ( self , name ) :
        self . _call_history += [ [ mediator_fake . create_knowledge_base , name ] ]
    def select_knowledge_base_for_editing ( self , name ) :
        self . _call_history += [ [ mediator_fake . select_knowledge_base_for_editing , name ] ]
    def entry_text_in_browser_request ( self ) :
        self . _creation_menu . entry_text_in_browser_reply ( self . _entry_text )

class creation_menu_tests :
    'creation_menu'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _creation_menu = creation_menu ( self . _mediator )
        self . _mediator . _creation_menu = self . _creation_menu
        
    #
    # show_creation_menu
    #
        
    def test_show_creation_menu_configure_title_text_for_browser ( self ) :
        self . _mediator . _creation_menu_title = 'my title'
        self . _creation_menu . show_creation_menu ( )
        self . _test . assume_equal ( self . _mediator . _configured_title_text_before_show_browser , 'my title' )
    def test_show_creation_menu_configure_action_text_for_browser ( self ) :
        self . _mediator . _creation_menu_create = 'my create'
        self . _creation_menu . show_creation_menu ( )
        self . _test . assume_equal ( self . _mediator . _configured_action_text_before_show_browser , 'my create' )
    def test_show_creation_menu_configure_action_title_name_text_for_browser ( self ) :
        self . _mediator . _creation_menu_new_name = 'my new name'
        self . _creation_menu . show_creation_menu ( )
        self . _test . assume_equal ( self . _mediator . _configured_action_title_name_text_before_show_browser , 'my new name' )
    def test_show_creation_menu_configure_only_unique_names_mode_for_browser ( self ) :
        self . _mediator . _creation_menu_already_exists = 'my already exists'
        self . _creation_menu . show_creation_menu ( )
        self . _test . assume_equal ( self . _mediator . _configured_only_unique_names_mode_before_show_browser , 'my already exists' )
    def test_show_creation_menu_configure_title_text_when_no_entries_for_browser ( self ) :
        self . _mediator . _creation_menu_title = 'my title'
        self . _creation_menu . show_creation_menu ( )
        self . _test . assume_equal ( self . _mediator . _configured_title_text_when_no_entries_before_show_browser , 'my title' )
    def test_show_creation_menu_configure_keep_action_part_when_no_entries_for_browser ( self ) :
        self . _creation_menu . show_creation_menu ( )
        self . _test . assume_true ( self . _mediator . _configured_keep_action_part_when_no_entries_before_show_browser )

    #
    # hide_creation_menu
    #
            
    def test_hide_creation_menu_hide_browser ( self ) :
        self . _creation_menu . hide_creation_menu ( )
        self . _test . assume_true ( self . _mediator . _hide_browser )

    #
    # on_browser_return
    #
        
    def test_on_browser_return_on_creation_menu_return ( self ) :
        self . _creation_menu . show_creation_menu ( )
        self . _creation_menu . on_browser_return ( )
        self . _test . assume_true ( self . _mediator . _on_creation_menu_return )
    def test_on_browser_return_do_nothing_before_show ( self ) :
        self . _creation_menu . on_browser_return ( )
        self . _test . assume_false ( self . _mediator . _on_creation_menu_return )
    def test_on_browser_return_do_nothing_after_hide ( self ) :
        self . _creation_menu . show_creation_menu ( )
        self . _creation_menu . hide_creation_menu ( )
        self . _creation_menu . on_browser_return ( )
        self . _test . assume_false ( self . _mediator . _on_creation_menu_return )
        
    #
    # on_browser_action
    #
        
    def test_on_browser_action_on_creation_menu_base_created ( self ) :
        self . _creation_menu . show_creation_menu ( )
        self . _creation_menu . on_browser_action ( )
        self . _test . assume_true ( self . _mediator . _on_creation_menu_base_created )
    def test_on_browser_action_on_creation_menu_base_created_called_last ( self ) :
        self . _creation_menu . show_creation_menu ( )
        self . _creation_menu . on_browser_action ( )
        self . _test . assume_equal ( self . _mediator . _call_history [ - 1 ] , mediator_fake . on_creation_menu_base_created )
    def test_on_browser_action_do_nothing_before_show ( self ) :
        self . _creation_menu . on_browser_action ( )
        self . _test . assume_false ( self . _mediator . _on_creation_menu_base_created )
    def test_on_browser_action_do_nothing_after_hide ( self ) :
        self . _creation_menu . show_creation_menu ( )
        self . _creation_menu . hide_creation_menu ( )
        self . _creation_menu . on_browser_action ( )
        self . _test . assume_false ( self . _mediator . _on_creation_menu_base_created )
    def test_on_browser_action_create_knowledge_base ( self ) :
        self . _mediator . _entry_text = 'my base'
        self . _creation_menu . show_creation_menu ( )
        self . _creation_menu . on_browser_action ( )
        self . _test . assume_equal ( self . _mediator . _call_history [ 0 ] , [ mediator_fake . create_knowledge_base , 'my base' ] )
    def test_on_browser_action_select_knowledge_base_for_editing ( self ) :
        self . _mediator . _entry_text = 'my base'
        self . _creation_menu . show_creation_menu ( )
        self . _creation_menu . on_browser_action ( )
        self . _test . assume_equal ( self . _mediator . _call_history [ 1 ] , [ mediator_fake . select_knowledge_base_for_editing , 'my base' ] )
